




/*
'===============================================================================
'  MP.LayerHelper.MP_OBS.BL.MbRoleDepartManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using MP.LayerHelper.MP_OBS.BLL;
using MP.LayerHelper.MP_OBS.DAL;
using MP.LayerHelper.MP_OBS.DAL.EntityClasses;
using MP.LayerHelper.MP_OBS.DAL.FactoryClasses;
using MP.LayerHelper.MP_OBS.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MP.LayerHelper.MP_OBS.BLL
{
	public class MbRoleDepartManagerBase : ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		
		public MbRoleDepartManagerBase()
		{
			// Nothing for now.
		}
		
		public override string TableName()
        {
            return "MbRoleDepart";
        }
		
		public MbRoleDepartEntity Insert(MbRoleDepartEntity _MbRoleDepartEntity)
		{
			return Insert(_MbRoleDepartEntity, "");
		}
		
		public MbRoleDepartEntity Insert(MbRoleDepartEntity _MbRoleDepartEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_MbRoleDepartEntity, true);
				MbRoleDepartFields field = new MbRoleDepartFields();
                LogEntity(_MbRoleDepartEntity, field, AcInsert, controlId);
			}
			return _MbRoleDepartEntity;
		}

		
		public MbRoleDepartEntity Insert(Guid Id, Guid RoleId, Guid DepartId)
		{
			MbRoleDepartEntity _MbRoleDepartEntity = new MbRoleDepartEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_MbRoleDepartEntity.Id = Id;
				_MbRoleDepartEntity.RoleId = RoleId;
				_MbRoleDepartEntity.DepartId = DepartId;
				MbRoleDepartFields field = new MbRoleDepartFields();
                LogEntity(_MbRoleDepartEntity, field, AcInsert);
				adapter.SaveEntity(_MbRoleDepartEntity, true);
			}
			return _MbRoleDepartEntity;
		}

		public MbRoleDepartEntity Insert(Guid RoleId, Guid DepartId)
		{
			MbRoleDepartEntity _MbRoleDepartEntity = new MbRoleDepartEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_MbRoleDepartEntity.RoleId = RoleId;
				_MbRoleDepartEntity.DepartId = DepartId;
				adapter.SaveEntity(_MbRoleDepartEntity, true);
				MbRoleDepartFields field = new MbRoleDepartFields();
                LogEntity(_MbRoleDepartEntity, field, AcInsert);
			}
			return _MbRoleDepartEntity;
		}
		
		public bool Update(MbRoleDepartEntity _MbRoleDepartEntity)
        {
            return Update(_MbRoleDepartEntity, "");
        }

		public bool Update(MbRoleDepartEntity _MbRoleDepartEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(MbRoleDepartFields.Id == _MbRoleDepartEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_MbRoleDepartEntity, filter);
				toReturn = true;
				
				MbRoleDepartFields field = new MbRoleDepartFields();
                LogEntity(_MbRoleDepartEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(MbRoleDepartEntity _MbRoleDepartEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_MbRoleDepartEntity, filter);
				toReturn = true;
				
				MbRoleDepartFields field = new MbRoleDepartFields();
                LogEntity(_MbRoleDepartEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(Guid Id, Guid RoleId, Guid DepartId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MbRoleDepartEntity _MbRoleDepartEntity = new MbRoleDepartEntity(Id);
				if (adapter.FetchEntity(_MbRoleDepartEntity))
				{
				
					_MbRoleDepartEntity.RoleId = RoleId;
					_MbRoleDepartEntity.DepartId = DepartId;
					adapter.SaveEntity(_MbRoleDepartEntity, true);
					toReturn = true;
					
					MbRoleDepartFields field = new MbRoleDepartFields();
					LogEntity(_MbRoleDepartEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(Guid Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MbRoleDepartEntity _MbRoleDepartEntity = new MbRoleDepartEntity(Id);
				if (adapter.FetchEntity(_MbRoleDepartEntity))
				{
					adapter.DeleteEntity(_MbRoleDepartEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("MbRoleDepartEntity", null);
			}
		}
		
		
		public int DeleteById(Guid Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MbRoleDepartEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByRoleId(Guid RoleId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MbRoleDepartEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDepartId(Guid DepartId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("MbRoleDepartEntity", filter);
			}
			return toReturn;
		}
		

		
		public MbRoleDepartEntity SelectOne(Guid Id)
		{
			MbRoleDepartEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				MbRoleDepartEntity _MbRoleDepartEntity = new MbRoleDepartEntity(Id);
				if (adapter.FetchEntity(_MbRoleDepartEntity))
				{
					toReturn = _MbRoleDepartEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbRoleDepartCollection = new EntityCollection(new MbRoleDepartEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbRoleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectAllLST()
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, null, 0, null);
			}
			return _MbRoleDepartCollection;
		}
		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _MbRoleDepartCollection;
		}


		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectByIdLST(Guid Id)
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, filter, 0, null);
			}
			return _MbRoleDepartCollection;
		}
		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectByIdLST_Paged(Guid Id, int PageNumber, int PageSize)
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MbRoleDepartCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(Guid Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbRoleDepartCollection = new EntityCollection(new MbRoleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbRoleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT_Paged(Guid Id, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbRoleDepartCollection = new EntityCollection(new MbRoleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbRoleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectByRoleIdLST(Guid RoleId)
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, filter, 0, null);
			}
			return _MbRoleDepartCollection;
		}
		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectByRoleIdLST_Paged(Guid RoleId, int PageNumber, int PageSize)
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MbRoleDepartCollection;
		}
		
		// Return DataTable
		public DataTable SelectByRoleIdRDT(Guid RoleId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbRoleDepartCollection = new EntityCollection(new MbRoleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbRoleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByRoleIdRDT_Paged(Guid RoleId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbRoleDepartCollection = new EntityCollection(new MbRoleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.RoleId == RoleId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbRoleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectByDepartIdLST(Guid DepartId)
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, filter, 0, null);
			}
			return _MbRoleDepartCollection;
		}
		
		// Return EntityCollection<MbRoleDepartEntity>
		public EntityCollection<MbRoleDepartEntity> SelectByDepartIdLST_Paged(Guid DepartId, int PageNumber, int PageSize)
		{
			EntityCollection<MbRoleDepartEntity> _MbRoleDepartCollection = new EntityCollection<MbRoleDepartEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_MbRoleDepartCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _MbRoleDepartCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDepartIdRDT(Guid DepartId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbRoleDepartCollection = new EntityCollection(new MbRoleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbRoleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByDepartIdRDT_Paged(Guid DepartId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _MbRoleDepartCollection = new EntityCollection(new MbRoleDepartEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(MbRoleDepartFields.DepartId == DepartId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_MbRoleDepartCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		

	}
}
